package com.javer.web.servlet;

import java.util.concurrent.atomic.AtomicInteger;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.javer.util.Constants;

/**
 * 当前在线人数统计
 * @author z3y2
 */
public class SimpleSessionListener implements HttpSessionListener {
	private final Log logger = LogFactory.getLog(getClass());
	private static AtomicInteger counter = new AtomicInteger(0);
	
	public SimpleSessionListener() {
		logger.info("在线人数统计监听器初始化完成");
	}

	public void sessionCreated(HttpSessionEvent evt) {
		evt.getSession().getServletContext().setAttribute(Constants.TotalOnlineCounter, counter.incrementAndGet());
	}

	public void sessionDestroyed(HttpSessionEvent evt) {
		evt.getSession().getServletContext().setAttribute(Constants.TotalOnlineCounter, counter.decrementAndGet());
	}
	
}
